//
//  YHTopView.m
//  FAKER
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 YHLai. All rights reserved.
//

#import "YHTopView.h"
#import "FitHeader.h"
#import "AllHeader.h"

@implementation YHTopView

- (instancetype)initWithFrame:(CGRect)frame YHSelected:(YHSelected *)yhSelected
{
    self = [super initWithFrame:frame];
    if (self) {
//        self.backgroundColor = [UIColor colorWithRed:0.97 green:0.97 blue:0.97 alpha:1];
        [self createViewsWithYHSelected:yhSelected];
        
        //添加夜间模式监听
        ADD_NSNOTIFICATIONCENTER_OBSERVER;
    }
    return self;
}

- (void)createViewsWithYHSelected:(YHSelected *)yhSelected
{
    _headImageView = [[BaseClassImageView alloc] initWithFrame:CGRectMake(20, 30, 40, 40)];
    [_headImageView sd_setImageWithURL:[NSURL URLWithString:[yhSelected.auther objectForKey:@"icon"]] placeholderImage:[UIImage imageNamed:@"PlaceHolder"]];
    [self addSubview:_headImageView];
    
    _usernameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_headImageView.X + _headImageView.WIDTH + 10, _headImageView.Y, 200, _headImageView.HEIGHT /2)];
    _usernameLabel.text = [yhSelected.auther objectForKey:@"name"];
    _usernameLabel.font = [UIFont systemFontOfSize:15];
    _usernameLabel.textColor = [[UIButton buttonWithType:UIButtonTypeSystem] titleColorForState:UIControlStateNormal];
    [self addSubview:_usernameLabel];
    
    _postTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_usernameLabel.X, _usernameLabel.Y + _usernameLabel.HEIGHT, _usernameLabel.WIDTH, _usernameLabel.HEIGHT)];
    _postTimeLabel.text = yhSelected.date;
    _postTimeLabel.font = [UIFont systemFontOfSize:13];
//    _postTimeLabel.textColor = [UIColor grayColor];
    [self addSubview:_postTimeLabel];
    
//    _listButton = [UIButton buttonWithType:UIButtonTypeSystem];
//    [_listButton setBackgroundImage:[UIImage imageNamed:@"common_icon_setting@2x"] forState:UIControlStateNormal];
//    _listButton.frame = CGRectMake(SCREEN_WIDTH - _headImageView.X - 30, 35, 30, 30);
//    [self addSubview:_listButton];
    
    [self changeColor];
}

- (void)changeColor
{
    if (NSUSERDEFAULTS_NIGHT) {
        self.backgroundColor = BGCOLOR_BLACK;
        _postTimeLabel.textColor = [UIColor lightGrayColor];
    }
    else {
        self.backgroundColor = [UIColor colorWithRed:0.97 green:0.97 blue:0.97 alpha:1];
        _postTimeLabel.textColor = [UIColor grayColor];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
